package com.zzk.lanouhn.myapplication1.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageView;

import com.zzk.lanouhn.myapplication1.R;
import com.zzk.lanouhn.myapplication1.modles.Guide;

/**
 * Created by lanouhn on 16/9/19.
 */
public class MessageArticleGuide extends AppCompatActivity{

    private ImageView iv_back;
    private WebView webView;
    private Guide guide;
    private String url;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_guide_article_message);
        iv_back= (ImageView) findViewById(R.id.iv_back_guide);
        webView= (WebView) findViewById(R.id.webview_guide);
        initData();
        initEvent();
    }
    private void initData(){
        Intent intent=getIntent();
        url=intent.getStringExtra("guideUrl");
        WebSettings webSettings = webView.getSettings();
        webSettings.setPluginState(WebSettings.PluginState.ON);
        webSettings.setUseWideViewPort(true);
        webSettings.setJavaScriptEnabled(true);
        webView.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
//        webview.loadUrl(url);
        //WebView加载web资源
        webView.loadUrl(url);
        //覆盖WebView默认使用第三方或系统默认浏览器打开网页的行为，使网页用WebView打开
        webView.setWebViewClient(new WebViewClient(){
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                // TODO Auto-generated method stub
                //返回值是true的时候控制去WebView打开，为false调用系统浏览器或第三方浏览器
                view.loadUrl(url);
                return true;
            }
        });
    }
    private void initEvent(){
        iv_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }
}
